<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 100px auto;
        }
    </style>
</head>

<body>
    <div></div>
    <script>
        //获取元素
        var div = document.querySelector('div');
        // 注册事件  处理程序
        var flag = 0;
        div.onclick = function () {
            if (flag == 0) {
                this.style.backgroundColor = 'purple';

                flag = 1;
            } else {
                this.style.backgroundColor = 'pink';

                flag = 0;
            }
        }
        var sum = 0;
        for (let i = 1; i <= 100; i++) {
            sum += i;
        }
        console.dir(sum)
    </script>
</body>

</html>